package com.yanqu.road.server.cmd.activity.autoreward.rank;

import com.yanqu.road.entity.rank.UnionActivityRank;
import com.yanqu.road.logic.cross.CrossUnionWarRankListModel;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.server.manager.unionwar.CrossUnionWarRankMgr;

import java.util.Map;

/**
 * @author ：zfr
 * @date ：2021/8/12 18:20
 */
public class CrossUnionWarActivityRank extends BaseCrossRank {

    public CrossUnionWarActivityRank(int activityId) {
        super(activityId);
    }

    @Override
    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg() {
        return null;
    }

    @Override
    public AutoSendRewardProto.CrossUnionRankMsg.Builder getCrossUnionRankMsg(int groupId) {
        AutoSendRewardProto.CrossUnionRankMsg.Builder msg = AutoSendRewardProto.CrossUnionRankMsg.newBuilder();
        msg.setActivityId(activityId);
        Map<Integer, Map<Integer, CrossUnionWarRankListModel>> map = CrossUnionWarRankMgr.getUnionWarRankListModelMap().get(activityId);
        if (map == null) {
            return msg;
        }
        for (Map.Entry<Integer, Map<Integer, CrossUnionWarRankListModel>> entry : map.entrySet()) {
            for (Map.Entry<Integer, CrossUnionWarRankListModel> modelEntry : entry.getValue().entrySet()) {
                if(modelEntry.getKey() != groupId){
                    continue;
                }
                CrossUnionWarRankListModel rankListModel = modelEntry.getValue();
                int conditionType = 0;
                if (entry.getKey() == 1) {
                    conditionType = 1000;
                } else if (entry.getKey() == 2) {
                    conditionType = 1001;
                }
                int rank = 0;
                for (UnionActivityRank rankData : rankListModel.getRankList()) {
                    String unionUid = rankData.getUnionUid();
                    rank++;
                    addUnionRankData(msg, conditionType, unionUid, rank);
                }
            }
        }
        return msg;
    }

    @Override
    public AutoSendRewardProto.CrossUnionRankMsg.Builder getCrossUnionRankMsg() {
        AutoSendRewardProto.CrossUnionRankMsg.Builder msg = AutoSendRewardProto.CrossUnionRankMsg.newBuilder();
        msg.setActivityId(activityId);
        Map<Integer, Map<Integer, CrossUnionWarRankListModel>> map = CrossUnionWarRankMgr.getUnionWarRankListModelMap().get(activityId);
        if (map == null) {
            return msg;
        }
        for (Map.Entry<Integer, Map<Integer, CrossUnionWarRankListModel>> entry : map.entrySet()) {
            for (Map.Entry<Integer, CrossUnionWarRankListModel> modelEntry : entry.getValue().entrySet()) {
                CrossUnionWarRankListModel rankListModel = modelEntry.getValue();
                int conditionType = 0;
                if (entry.getKey() == 1) {
                    conditionType = 1000;
                } else if (entry.getKey() == 2) {
                    conditionType = 1001;
                }
                int rank = 0;
                for (UnionActivityRank rankData : rankListModel.getRankList()) {
                    String unionUid = rankData.getUnionUid();
                    rank++;
                    addUnionRankData(msg, conditionType, unionUid, rank);
                }
            }
        }
        return msg;
    }
}
